﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Stock
{	public partial class ShiftsOutFree : Form
	{	private	DIProject.DataSets.Stock.ShiftsOutFreeRow shiftOutDoc{get{return docsGridView.CurrentCell != null? stock.ShiftsOutFree[docsGridView.CurrentCell.RowIndex]: null;}}
		public	DateTime DocDate{get{return shiftOutDoc != null? shiftOutDoc.DocDate: DateTime.MinValue;}}
		public	string DocNumber{get{return shiftOutDoc != null? shiftOutDoc.DocNumber: null;}}

		public ShiftsOutFree()
		{	InitializeComponent();
		}

		private void ShiftsOutFree_Load(object sender, EventArgs e)
		{	try
			{	shiftsOutFreeTableAdapter.Fill(stock.ShiftsOutFree);
			}
			catch(Exception ex)
			{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}

		}

		private void docsGridView_KeyDown(object sender, KeyEventArgs e)
		{	if(e.KeyCode == Keys.Enter)
				e.Handled = true;
		}

		private void docsGridView_KeyPress(object sender, KeyPressEventArgs e)
		{	if(e.KeyChar == '\r' && docsGridView.CurrentCell != null)
			{	DialogResult = DialogResult.OK;
				Close();
			}
		}

		private void docsGridView_MouseDoubleClick(object sender, MouseEventArgs e)
		{	DataGridView.HitTestInfo hit = docsGridView.HitTest(e.X, e.Y);
			if(hit.Type == DataGridViewHitTestType.Cell)
			{	docsGridView.CurrentCell = docsGridView.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
				DialogResult = DialogResult.OK;
				Close();
			}
		}
	}
}